home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Prograph Classic 2.6.1 / Examples / db_example / db example code.ReadMe < prev    next >
Encoding:
Text File  |  1994-10-21  |  3.7 KB  |  61 lines  |  [TEXT/ttxt]

  1. Example:      DB example code ƒ
  2. Written by:  Prograph International (Mark Szpakowski)
  3. Contents:     DB example code.pgs
  4.                     videos.txt
  5.                     videosDB
  6.                     videosDB keys
  7.                    DB example code.ReadMe
  8.  
  9. Needs Prograph Extensions:
  10.                     Math Primitives
  11.                     More Primitives
  12.                     Primitives
  13.                     Datafile Primitives
  14.  
  15. Needs Libraries to Compile:
  16.                     Library 2.6
  17.  
  18. How to Use in Your Program:
  19.     Selectively load any method or class that seems useful.
  20.  
  21. DESCRIPTION
  22.  
  23.  DB example code.pgs contains the example code fragments used as part of the Database Engine primitives documentation, as well as a few other useful and illustrative methods.  It is deliberately kept very simple:  it assumes that at any one time there is only one database, one table and one key that is open, the path ID of which can be accessed in the persistent "current db", "current table" and "current key"  respectively.  The videos.txt file is a text-only file with a few videos records in tab-delimited format.  This file was imported into the videosDB database via the "table-import" primitive, into the "videos" table.  Each cluster of that table is an instance of class "videos".
  24.  
  25.  
  26. PERSISTENTS
  27.  
  28. current-DB
  29.  
  30. current-table
  31.  
  32. current-key          The videos database provided has two key attributes, "Artist" (string, case-insensitive by default) and ID (natural number (integer > 0)).  Be sure to set the current-key to be the key you want to work with.  
  33.  
  34. current-cluster    In the example code provided, current-cluster is used only to store the cluster ID of the currently referenced cluster.
  35.  
  36.  
  37. CLASS "path"
  38.  
  39. •  Instance Attributes:  name, ID, owner
  40.   Database entities have names (useful on the user level), path IDs (required by the database primitives), and owners (databases could belong to an application, tables belong to databases, and keys belong to tables).
  41.  
  42. • error?
  43.   Succeeds if error number 0 (database operation succeeded) is reported.  Otherwise it fails, after indicating whether a file (error # < 0) or database (error # > 0) occurred.  This failure usually triggers immediate termination of the method in which it occurs.  One of the first improvements that could be made, of course, would be to provide a full-text error message for each database error that can occur.
  44.  
  45.  
  46. CLASS "database" (inherits from "path")
  47.  
  48. •  Class Attributes: databases, current DB
  49.   The class attribute "databases" could be used to store a list of databases, while "current DB" could be used to refer to the (one) database currently in use (this would provide an alternative and somewhat more flexible way of referring to paths than that provided by using persistents).  A further extension would be to maintain a library list and an "active" (those that are open) list of databases.
  50.  
  51. •  Instance Attribute:  tables
  52.     A list of tables belonging to the database.
  53.  
  54. •  find all by key
  55.     Finds all the clusters that have the same value for the key "Artist".  Asks the user for that value, and then puts together a list of cluster values (instances of class "videos"), which, after telling the user how many clusters it found, it displays via the "display" primitive.  Note that the comparison routine it uses to determine whether the key being read by "key-next" is still the one requested by the user is a case-insensitive string comparison routine; this routine will not work with a key that is not a string.  
  56.  
  57. This method assumes you have 1) opened the "videosDB" database (use "open db"), 2) opened the "videos" table (use "open table"), and 3) opened the "Artist" key (use "open key").
  58.  
  59. •  list all keys
  60.   List all the keys for the "videos" table (eliminating redundant entries).
  61.